﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace MyWeb.Data
{
	public class MenuDAL : SqlDataProvider
	{

		#region[Menu_GetbyAll]
		public DataTable Menu_GetByAll()
		{
			using (var cmd = new SqlCommand("sp_Menu_GetByAll", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[Menu_GetbyId]
        public DataTable Menu_GetById(string Id)
		{
			using (var cmd = new SqlCommand("sp_Menu_GetById", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Id", Id));
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[Menu_GetbyTop]
		public DataTable Menu_GetByTop(string Top, string Where, string Order)
		{
			using (var cmd = new SqlCommand("sp_Menu_GetByTop", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				cmd.Parameters.Add(new SqlParameter("@Top",Top));
				cmd.Parameters.Add(new SqlParameter("@Where",Where));
				cmd.Parameters.Add(new SqlParameter("@Order",Order));
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[Menu_Insert]
		public void Menu_Insert(MenuInfo Data)
		{
			using (var cmd = new SqlCommand("sp_Menu_Insert", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Name", Data.Name));
				cmd.Parameters.Add(new SqlParameter("@Link", Data.Link));
				cmd.Parameters.Add(new SqlParameter("@Order", Data.Order));
				cmd.Parameters.Add(new SqlParameter("@ParentId", Data.ParentId));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
		#region[Menu_Update]
		public void Menu_Update(MenuInfo Data)
		{
			using (var cmd = new SqlCommand("sp_Menu_Update", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Id", Data.Id));
				cmd.Parameters.Add(new SqlParameter("@Name", Data.Name));
				cmd.Parameters.Add(new SqlParameter("@Link", Data.Link));
				cmd.Parameters.Add(new SqlParameter("@Order", Data.Order));
				cmd.Parameters.Add(new SqlParameter("@ParentId", Data.ParentId));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
		#region[Menu_Delete]
		public void Menu_Delete(String Id)
		{
			using (var cmd = new SqlCommand("sp_Menu_Delete", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Id", Id));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
	}
}